#include "RotateAnimator.h"
#include "../../include/ISceneNode.h"

CRotateAnimator::CRotateAnimator(vector3dvpos &RotationIni,vector3dvpos &RotationFin,u32 Time):RotIni(RotationIni),RotFin(RotationFin),
TimeToWork(Time),TimeBegin(0)
{
}

CRotateAnimator::~CRotateAnimator()
{

}

bool CRotateAnimator::AnimateNode(u32 Time,ISceneNode *Node)
{
	if (!TimeBegin)
		TimeBegin = Time;

	Elapsed = Time - TimeBegin;

    vPos Alpha = 0;
	if (Elapsed)
		Alpha = (vPos)((vPos)Elapsed) / ((vPos)TimeToWork);

    if (Elapsed <= TimeToWork)
    {
		Node->SetRotation(RotIni.X + ((RotFin.X - RotIni.X) * Alpha),
			RotIni.Y + ((RotFin.Y - RotIni.Y) * Alpha),
			RotIni.Z + ((RotFin.Z - RotIni.Z) * Alpha));
	}

	if (Elapsed >= TimeToWork)
	{
		Node->SetRotation(RotFin);
		return true;
	}
	else
		return false;
}
